<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "config/config.php";
include "auth.php";
include "DBManager.php";

// -----------------------------------------------------------------------------
// 访问设置
// -----------------------------------------------------------------------------

if (!isset($_POST['linkId']) || !isset($_POST['linkTitle']) || !isset($_POST['linkUrl'])) {
    exit("需要传入有效的参数！");
}

$linkId = $_POST['linkId'];
$linkTitle = $_POST['linkTitle'];
$linkUrl = $_POST['linkUrl'];

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------
// 时区设置
// -----------------------------------------------------------------------------

date_default_timezone_set($region);

$timeClick = (string)time();

// -----------------------------------------------------------------------------

/* 第一步，记录点击事件 */
$arr = compact("linkId", "linkTitle", "linkUrl", "timeClick");
$db->insertIntoClickLog($arr);

/* 第二步，增加 timesOfClick */
$db->increaseLinkTimesOfClick($linkId);

/* 第三步，记录 timeLastClick */
$db->changeLinkAttrTimeLastClick($linkId, $timeClick);
